<?php

namespace App\B2BProject\Custom\Business;

use Illuminate\Database\Eloquent\Model;

/**
 * Class PriceStrategy
 *
 * 价格策略
 *
 * @package App\B2BProject\Custom\Business
 */
class PriceStrategy extends Model
{
    protected $guarded = ['id', 'created_at', 'updated_at'];
    /**
     * 已授权的数据表，可通过该表获取商品信息
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function licensedGoods()
    {
        return $this->hasMany('App\B2BProject\Custom\Business\LicensedGood', 'strategy_id', 'id');
    }

    public function delete()
    {
        // 首先删除使用该价格策略对应授权的商品
        $this->licensedGoods()->delete();

        return parent::delete();
    }
}
